<%@ page import="java.util.Set" %>
<%@ page import="com.hyy.taobao.api.entity.MyCart" %>
<%@ page import="com.hyy.taobao.api.entity.User" %>
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2021/4/14
  Time: 9:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>购物车</title>
    <style>
        .right {
            display: inline-block;

        }

        table {
            display: inline-block;
        }
    </style>
</head>
<body>
<h3>${msg}</h3>
<hr>

<table border="1">
    <tr>
        <th>商品名称</th>
        <th>商品单价</th>
        <th>商品数量</th>
    </tr>
    <c:if test="${myCartSet!=null}">
        <c:forEach items="${myCartSet}" var="myCart">
            <c:if test="${myCart != null}">
                <tr>
                    <td>${myCart.goodsName}</td>
                    <td>${myCart.goodsPrice}</td>
                    <td>${myCart.goodsNumber}</td>
                    <td>
                        <form action="/deleteGoods" class="right">
                            <input type="hidden" name="goodsName" value="${myCart.goodsName}">
                            <input type="hidden" name="judgement" value="-1">
                            <button type="submit">-</button>
                        </form>
                    </td>
                    <td>
                        <form action="/deleteGoods" class="right">
                            <input type="hidden" name="goodsName" value="${myCart.goodsName}">
                            <input type="hidden" name="judgement" value="0">
                            <button type="submit">删除该商品</button>
                        </form>
                    </td>
                    <td>
                        <form action="/deleteGoods" class="right">
                            <input type="hidden" name="goodsName" value="${myCart.goodsName}">
                            <input type="hidden" name="judgement" value="1">
                            <button type="submit">+</button>
                        </form>
                    </td>
                </tr>
            </c:if>
            <c:if test="${myCart == null}">
                <h3>空</h3>
            </c:if>
        </c:forEach>
        <c:if test="${myCartSet == null}">
            <h3>空</h3>
        </c:if>
    </c:if>
</table>

<h3>商品总价：
    <c:set scope="request" var="sum" value="0"/>
    <c:if test="${myCartSet!=null}">
        <c:forEach items="${myCartSet}" var="myCart">
            <c:if test="${myCart!=null}">
                <c:set scope="request" var="goods" value="${myCart.goodsNumber*myCart.goodsPrice}"></c:set>
                <c:set scope="request" var="sum" value="${requestScope.sum+requestScope.goods}"></c:set>
            </c:if>
        </c:forEach>
        ${requestScope.sum}元
    </c:if>
    <c:if test="${myCartSet==null}">
        0元
    </c:if>
</h3>
<form action="/deleteGoods" class="right">
    <input type="hidden" name="judgement" value="10">
    <button type="submit">清空购物车</button>
</form>

<form action="taobaoIndex.jsp" method="post">
    <button>返回首页</button>
</form>

</body>
</html>
